home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4ZXEX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-13
|
5KB
|
202 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4z4ex.c
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains the expander for the ZIP4 cross reference file.
// This module should not use any global variables since it must be
// re-entrant.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Description: Read a compressed record from the output buffer.
// Parameters: pblk Decoder data structure
// pctyst ZIP5 record
// Returns: TRUE if successful.
// FALSE if no more records found to decode.
//----------------------------------------------------------------------------
BOOL FN_E Z4ZXExpand(PZ4_ZX_BLK pblk, PZ4_ZX pzx)
{
PBYTE pb;
SIZET cb;
ULONG ulDelta;
USHORT usDelta = 0;
BOOL fDelta;
CHAR szZip4[MAX_ZIP4+1];
USHORT usAddonLo, usAddonHi;
Assert(pblk && pzx);
memset(pzx, 0, sizeof(pzx));
// Must be at end of buffer
if (pblk->cbNext >= pblk->cb)
return FALSE;
pb = pblk->pb + pblk->cbNext;
if (pb[0] == 0) // Block not full, but no more records
{
pblk->cbNext = pblk->cb;
return FALSE;
}
//
// Decode record
//
ulDelta = (ULONG)(pb[0] & 0x3F);
fDelta = (pb[0] & 0x40) != 0;
if (pb[0] & 0x80)
{
pb++;
ulDelta += (((ULONG)pb[0]) << 6);
pb++;
ulDelta += (((ULONG)pb[0]) << 14);
pb++;
ulDelta += (((ULONG)pb[0]) << 22);
pb++;
}
else
pb++;
pblk->ulZip4 += ulDelta;
sprintf(szZip4, "%09lu", pblk->ulZip4);
strcpy(pblk->zx.szAddonLo, szZip4 + MAX_ZIP5);
usAddonLo = (USHORT)atoi(pblk->zx.szAddonLo);
szZip4[MAX_ZIP5] = '\0';
strcpy(pblk->zx.szZip5, szZip4);
//
// Get high range delta
//
if (fDelta)
{
usDelta = (USHORT)(pb[0] & 0x7F);
if (pb[0] & 0x80)
{
pb++;
usDelta += (USHORT)(((USHORT)pb[0]) << 7);
pb++;
}
else
pb++;
usDelta++;
}
usAddonHi = usAddonLo + usDelta;
sprintf(pblk->zx.szAddonHi, "%04u", usAddonHi);
//
// Get record count
//
cb = (SIZET)(pb[0] & 0x7F);
if (pb[0] & 0x80)
{
pb++;
cb += (((SIZET)pb[0]) << 7);
pb++;
}
else
pb++;
cb++;
//
// Decode record ids
//
if (!RecIdDecode(pblk->zx.arecid, MAX_ZIP4_RECS, pb, cb, &pblk->zx.cRecords, &pblk->recid))
return FALSE;
Assert(pblk->zx.cRecords <= MAX_ZIP4_RECS);
pb += cb;
//
// Finish up
//
cb = (SIZET)(pb - pblk->pb);
Assert(cb <= pblk->cb);
pblk->cbNext = cb;
*pzx = pblk->zx; // Return a copy of the current record
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize ZIP5 expander
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4ZXExpandInitialize(PZ4_ZX_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_ZX_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Reset ZIP4 cross reference expander to decode another
// block of data.
// Parameters: pblk Decoder data structure
// pb Buffer containing compressed data.
// cb Size of buffer.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4ZXExpandReset(PZ4_ZX_BLK pblk, PBYTE pb, SIZET cb)
{
Assert(pblk);
pblk->pb = pb; // Set decoding pointers
pblk->cb = cb;
pblk->cbNext = 0;
pblk->ulZip4 = 0;
pblk->recid.usOffset = 0;
pblk->recid.lBlock = 0;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Terminate ZIP5 expander.
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4ZXExpandTerminate(PZ4_ZX_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_ZX_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------